Using Curve Error When Converting Paths to Polygons
You can use the curve error property of the style object in a variety of situations--for example, when approximating a path shape (which includes curves) with a polygon shape (which includes only straight lines).The
GXSetShapeType
function, which is described in full in Inside Macintosh: QuickDraw GX Objects, allows you to convert a shape from one shape type to another. When you convert a path shape that contains curves to a polygon shape, QuickDraw GX uses the curve error of the shape's style to determine how close to make the polygon approximation. The distance between the polygon and the original path is never greater than the number of grid points (1/72-inch units) specified by the curve error.Listing 3-5 shows a sample function that creates a circular path shape, sets its curve error to 1, and converts it to a polygon shape.
Listing 3-5 Converting a circle to a polygon
void ConvertCircleToPolygon(void) { gxRectangle circleBounds = {ff(50), ff(50), ff(200), ff(200)}; gxShape aCircle; aCircle = NewArc(&circleBounds, ff(0), ff(360), false); GXSetShapeFill(aCircle, gxClosedFrameFill); GXSetShapeCurveError(aCircle, ff(1)); GXSetShapeType(aCircle, gxPolygonType); GXDrawShape(aCircle); GXDisposeShape(aCircle); }Since the curve error is 1 in this example, the resulting polygon is never more than 1 grid point away from the original circle, which makes for an accurate approximation, as shown in Figure 3-39.Figure 3-39 Polygon approximation of a circle with curve error of 1
Increasing the curve error decreases the accuracy of the approximation. Setting the curve error to 5 in this example creates the polygon shown in Figure 3-40, which has fewer sides than the polygon in Figure 3-39.
Figure 3-40 Polygon approximation of a circle with curve error of 5
If you increase the curve error to 10, the octagon shown in Figure 3-41 results.
Figure 3-41 Polygon approximation of a circle with curve error of 10
Although decreasing the curve error leads to more accurate approximations in general, a curve error of 0 is a special case. A curve error of 0 indicates that QuickDraw GX should not approximate the path at all. Instead, QuickDraw GX simply removes all off-curve control points, leaving a polygon made up of the on-curve geometric points of the initial path.
In Listing 3-5, the circular path returned by the
NewArc
library routine contains eight off-curve control points, which imply eight on-curve geometric points midway between each pair of off-curve control points. A curve error of 0 results in a polygon containing these eight on-curve points, as shown in Figure 3-42.Figure 3-42 Polygon resulting from a curve error of 0
For more information about paths, polygons, and on-curve and off-curve geometric points, see Chapter 3, "Geometric Shapes."
For more information about curve error and the functions you can use to manipulate it, see "Curve Error" on page 3-14 and "Getting and Setting Curve Error" on page 3-114.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help